//view js
var rootPath = getRootPath();
var isRightPhoneNum = false;
$(function(){
	//获取跳转系统
	var system = getParentUrlParam("system");
	//第三方绑定
	var isPhone = isPhoneScreen();
	$.ajax({
		url: rootPath + '/user/queryUserself',
		type: 'GET',
		contentType: 'application/json;charset=UTF-8',
		success: function(data) {
			if(data.returnCode == '0000') {
				var user = data.returnObject;
				uid = user.uid;
				var unionid = user.unionid;
				if(unionid == '' || unionid == undefined) {
					$("#rWord").html("绑定");
				} else {
					if(user.nickName == undefined || user.nickName == null || user.nickName == "null") {
						$("#unionid").html("");
					} else {
						$("#unionid").html(user.nickName);
					}
					$("#rWord").html("解绑");
					$("#isBindWX").val(1);
				}
				if(!isPhone) {
//					createQR(uid);
					createQR(uid,system);
					if(user.headimgurl != null && user.headimgurl != undefined ) {
						$("#headimgurl").prop("src", rootPath + "/file/viewimg?fileName=" + user.headimgurl + "&type=1");
					}
					//页面"昵称"对应数据库uname,数据库nickName对应"微信用户"昵称
					$("#nickName").html(user.uname);
					if(unionid != undefined && unionid != '') {
						if(user.nickName == undefined || user.nickName == null || user.nickName == "null") {
							$("#unionid").html("");
						} else {
							$("#unionid").html(user.nickName);
						}
					}
					$("#authPhone").html(user.phone);
				}
			}
		},
		error: function(jqXHR,textStatus,errorThrown){
			layer.alert("error");
		}
	});
	
});
//function createQR(uid) {
function createQR(uid,system) {
	var width = window.screen.width;
	var href = rootPath + "/normal/css/layouts/";
	if(width > 600) {
		href += "bindWx/_all.css";
	} else {
		href += "menu/_all.css"; 
	}
	
	var redirectUri = redirect_uri;
	if(system != null && system != '' && system.toLowerCase() == 'scfire') {
		redirectUri += encodeURIComponent("?system=scfire")
	}
	
	var obj = new WxLogin({
		id:"wx",//div的id
		appid : appid,
		scope : scope,
//		redirect_uri : redirect_uri,
		redirect_uri : redirectUri,
		state : hex_md5("bind" + uid) + "_" + uid,
		style : style,        
		href : href
	 });
}
/**
 * 检查屏幕
 * > 600  电脑
 * @returns
 */
function isPhoneScreen() {
	var width = window.screen.width;
	var isPhone = false;
	if(width < 601) {
		isPhone = true;
	}
	return isPhone;
}